﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.DataVisualization.Charting;
using BusinessComponents.Managers;
using BusinessComponents.DomainModels;

namespace WaterfrontLodge.WebForms.Report
{
    public partial class RPT1002 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DateTime firstDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
                txtDateFrom.Text = firstDate.ToShortDateString();
                txtDateTo.Text = firstDate.AddMonths(1).AddDays(-1).ToShortDateString();
            }

            Chart1.ImageStorageMode = System.Web.UI.DataVisualization.Charting.ImageStorageMode.UseImageLocation;

            Chart1.Series["Series1"].ChartType = SeriesChartType.Bar;
            Chart1.Titles[0].Text = "Occupation Rate";
            Chart1.Titles[0].ToolTip = "Occupation Rate by Room Number";

            foreach (var rpt in ManagerFactory.ReportMgr.fetchRpt1002(Convert.ToDateTime(txtDateFrom.Text), Convert.ToDateTime(txtDateTo.Text)))
            {
                int pos = Chart1.Series["Series1"].Points.AddXY(rpt.RoomNo, rpt.OccupationRate);
                Chart1.Series["Series1"].Points[pos].Label = rpt.OccupationRate.ToString("P2");
            }

            Chart1.Series["Series1"]["DrawingStyle"] = "Cylinder";
            Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
            Chart1.DataBind();
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {

        }
        #endregion

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/WebForms/Report/ReportList.aspx", true);
        }
    }
}